<?php namespace Home\Controller;

use Hdphp\Controller\Controller;

class LoginController extends Controller{
	
	
	public function index(){
		if(IS_POST){
			$account = Q('post.account');
			$pwd = Q('post.password','','md5');
			$code = Q('post.captcha');
			$check = Db::table('user')->where("account='{$account}' AND pwd='{$pwd}'")->get();
			if($check AND $_SESSION['code'] == $code){
				$_SESSION['account'] = $check[0]['account'];
				$_SESSION['cusid'] = $check[0]['cusid'];
				go(U('Index/index'));
			}else{
				echo "用户或密码错误或验证码错误！";
			}
		}
		View::make();
	}
	
	public function logout(){
		unset($_SESSION['account']);
		unset($_SESSION['cusid']);
		go(U('Index/index'));
	}
	public function code(){
		Code::make();
	}
	
} 



 ?>